import { ElMessageBox } from 'element-plus';

interface ConfirmConfig {
    title: string,
    type?: string,
    confirmButtonText?: string,
    cancelButtonText?: string,
    confirmCallback: Function,
    cancelCallback?: Function
}


const confirm = (config: ConfirmConfig) => {
    ElMessageBox
        .confirm(
            config.title,
            config.type || '操作提示',
            {
                confirmButtonText: config.confirmButtonText || '确认',
                cancelButtonText: config.confirmButtonText || '取消',
                type: 'warning',
            }
        )
        .then(() => {
            config.confirmCallback();
        })
        .catch(() => {
            if (config.cancelCallback) {
                config.cancelCallback();
            }
        }
    )
}

const alert = (message: string) => {
    ElMessageBox.alert(message, '提示', {
        confirmButtonText: '确定'
    })
}

export {
    confirm, alert
}